package com.perceptivesoftware.licensing.client.common.util;

import java.util.Date;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.user.client.Cookies;

public class ClientUtils {

	public static MessageBox yesNoCancelMessageBox(final String title, final String msg, final Listener<MessageBoxEvent> callback) {
		final MessageBox box = new MessageBox();
		box.setTitle(title);
		box.setMessage(msg);
		box.addCallback(callback);
		box.setIcon(MessageBox.QUESTION);
		box.setButtons(MessageBox.YESNOCANCEL);
		box.show();
		return box;
	}

	public static void setRoleCookie(final String roleValCode) {
		if (roleValCode == null) {
			Cookies.setCookie(ClientConstants.CHANGETO_ROLEVAL_COOKIE_NAME, "", new Date(), null, "/", false);
		}
		else {
			Cookies.setCookie(ClientConstants.CHANGETO_ROLEVAL_COOKIE_NAME, roleValCode, null, null, "/", false);
		}
	}

	public static String getRoleCodeFromCookieAndClearIt() {
		final String roleValCode = Cookies.getCookie(ClientConstants.CHANGETO_ROLEVAL_COOKIE_NAME);
		setRoleCookie(null);
		return roleValCode;
	}
}
